from flask import jsonify


def result(error_code=0, data=None, error=None):
    """
    api 结果返回结果
    :param error_code:
    :param data:
    :param error:
    :return:
    """

    result_json = {'error_code': error_code}
    if error:
        result_json['error'] = error
    if data:
        if isinstance(data, dict):
            result_json = {**data, **result_json}
        else:
            result_json['data'] = data
    return jsonify(result_json)


def error(error_code, error=None):
    return result(error_code, error=error)


def success(data):
    return result(data=data)
